<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./lib/dist/include-openlayers-local.js"></script>
  </head>
  <body>
    <div id="map"></div>
    <script>
      const gdbps = ['gdbp://MapGISLocalPlus/demo1219/sfcls/point']
      const VecLayer = new Zondy.Map.GdbpLayer('', gdbps, {
        ip: 'localhost',
        port: 6163
      })
      const map = new ol.Map({
        target: 'map',
        layers: [VecLayer],
        view: new ol.View({
          projection: 'EPSG:4326',
          center: [117, 26],
          zoom: 4
        })
      })
      var Point2 = []
      var source2
      var vector2
      map.on('click', function (e) {
        var point = new ol.Feature({
          geometry: new ol.geom.Point([e.coordinate[0], e.coordinate[1]])
        })
        var style = new ol.style.Style({
          image: new ol.style.Circle({
            radius: 20,
            fill: new ol.style.Fill({
              color: '#ffcc33'
            })
          })
        })
        Point2.push(point)
        source2 = new ol.source.Vector({
          features: [...Point2]
        })

        if (vector2) {
          map.removeLayer(vector2)
        }
        vector2 = new ol.layer.Vector({
          source: source2
        })
        vector2.setStyle(style)
        map.addLayer(vector2)
        var editService = new Zondy.Service.EditDocFeature('gdbps', e, {
          ip: 'localhost',
          port: 6163
        })
        console.log(editService)
        //执行添加点要素集
        editService.add(Point2, onPntSuccess)
      })
      function onPntSuccess(data) {
        if (data.succeed) {
          alert('添加成功')
          cityLayer.refresh() //重新加载地图文档
        } else {
          alert('添加点要素失败')
        }
      }
    </script>
  </body>
</html>
